﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using EF.Model;
using EF.Model.Base;
using EF.DAL.Base;

namespace EF.BLL.Base
{
    public class RoleService
    {
        private RoleDAO roleDAL = new RoleDAO();

        /// <summary>
        /// 获取角色Id和角色名
        /// </summary>
        /// <param name="lang">语言</param>
        /// <returns></returns>
        public DataTable GetShortList(string lang)
        {
            return roleDAL.GetShortList(lang);
        }

        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <param name="lang">语言标识</param>
        /// <param name="columns">返回列头</param>
        /// <param name="pageIndex">翻页</param>
        /// <param name="pageSize">每页记录行数</param>
        /// <param name="orderBy">排序字段</param>
        /// <param name="rowsCount">记录总数</param>
        /// <returns></returns>
        public DataTable GetRoleList(string lang, string columns, int? pageIndex, int? pageSize, string orderBy, out int rowsCount)
        {
            return roleDAL.GetRoleList(lang, columns, pageIndex, pageSize, orderBy, out rowsCount);
        }

        /// <summary>
        /// 获取角色Model
        /// </summary>
        /// <param name="lang">语言</param>
        /// <param name="roleId">角色Id</param>
        /// <returns></returns>
        public RoleModel GetModel(string lang, int roleId)
        {
            return roleDAL.GetModel(lang, roleId);
        }

        /// <summary>
        /// 角色新建
        /// </summary>
        /// <param name="model">角色Model</param>
        /// <returns>1,新建成功;2,新建失败,用户名已存在;0,新建失败,数据库异常.</returns>
        public int Add(RoleModel model, string lang, out string msg)
        {
            return roleDAL.Add(model, lang, out msg);
        }

        /// <summary>
        /// 角色编辑
        /// </summary>
        /// <param name="model">角色Model</param>
        /// <returns>1,编辑成功;0,编辑失败,数据库异常.</returns>
        public int Edit(RoleModel model, string lang, out string msg)
        {
            return roleDAL.Edit(model, lang, out msg);
        }

        /// <summary>
        /// 角色逻辑删除
        /// </summary>
        /// <param name="roleIds">被逻辑删除角色Id</param>
        /// <param name="updateUser">执行逻辑删除用户Id</param>
        /// <returns>1,逻辑删除成功;0,逻辑删除失败,数据库异常.</returns>
        public int LogicDel(string roleIds, int updateUser, string lang, out string msg)
        {
            return roleDAL.LogicDel(roleIds, updateUser, lang, out msg);
        }

        /// <summary>
        /// 获取功能点树
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <param name="lang">语言</param>
        /// <returns></returns>
        public DataTable GetFunctionTree(int roleId, string lang)
        {
            return roleDAL.GetFunctionTree(roleId, lang);
        }

        /// <summary>
        /// 设置权限
        /// </summary>
        /// <param name="funcRoleId">功能点Id</param>
        /// <param name="roleId">角色Id</param>
        /// <param name="lang">语言</param>
        /// <returns>1,设置成功;0,设置失败,数据库异常.</returns>
        public int SetFunctionRole(string funcRoleId, int roleId, int userId, string lang, out string msg)
        {
            return roleDAL.SetFunctionRole(funcRoleId, roleId, userId, lang, out msg);
        }
    }
}
